﻿using Data;
using Hero;
using Logic;
using UnityEngine;

namespace Level.Bonuses
{
    public class Gun : MonoBehaviour
    {
        public int Value { get; set; }
        private GameSceneData _data;
        private HeroState _state;
        private HeroShoot _heroShoot;
        private HeroScore _heroScore;

        public void Construct(GameSceneData data, HeroState state, HeroScore heroScore, HeroShoot heroShoot)
        {
            _data = data;
            _state = state;
            _heroShoot = heroShoot;
            _heroScore = heroScore;
        }

        private void OnTriggerEnter(Collider other)
        {
            if (!other.CompareTag(Constants.PlayerTag)) 
                return;
            if (_state.CurrentGuns < _state.MaxGuns)
            {
                _state.CurrentGuns++;
                _heroShoot.InitGuns();
            }
            _heroScore.SetScore(Value);
            _data.LootPieces.Remove(gameObject);
            Destroy(gameObject);
        }
    }
}
